package base.day19.array;

import java.util.ArrayList;
import java.util.Collection;

public class Collection1 {
    public static void main(String[] args) {
        Collection<String> collection=new ArrayList<>();
        collection.add("aaa");
        collection.add("bbb");
        collection.add("ccc");
        System.out.println(collection);
        //remove删除指定元素
        boolean result=collection.remove("aaa");
        boolean result2=collection.remove("eee");
        System.out.println(result);
        System.out.println(result2);
        System.out.println(collection);

        //removeif用lambda删除符合条件的元素
        collection.add("vvvv");
        collection.removeIf(
                (String s)->{
                    return s.length()==3;
                }
        );
        System.out.println(collection);

        //clear清空集合
        collection.clear();
        System.out.println(collection);


        collection.add("aaa");
        collection.add("bbb");
        collection.add("ccc");
        //contains 判断集合中是否存在指定元素
        boolean contains = collection.contains("aaa");
        boolean contains2= collection.contains("sss");
        System.out.println(contains);
        System.out.println(contains2);

        //isempty 判断集合是否为空
        boolean empty = collection.isEmpty();
        System.out.println(empty);

        //size 集合的长度元素个数
        int size = collection.size();
        System.out.println(size);
    }
}
